package gdut.edu.expression;

import gdut.edu.domain.UserLogin;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description 自定义权限
 * @Author JiaFu
 * @Date 2022/7/6 9:41
 */
@Component("ex")
public class JFExpressionRoot {
    public boolean hasAuthority(String authority){
//        获取当前用户权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        UserLogin userLogin = (UserLogin) authentication.getPrincipal();
        List<String> permissions = userLogin.getPermissions();
//        判断权限集合中是否存在authority
        return permissions.contains(authority);
    }
}
